package com.bugu.web.customer;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import org.springside.modules.security.springsecurity.SpringSecurityUtils;
import org.springside.modules.web.struts2.CRUDActionSupport;

import com.bugu.entity.customer.Company;
import com.bugu.service.customer.CompanyManager;
@SuppressWarnings("serial")
@Results( { @Result(name = CRUDActionSupport.RELOAD, location = "company", type = "redirect") })
public class CompanyAction extends CRUDActionSupport<Company> {
	
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	public void prepareList() throws Exception{
		loginName = SpringSecurityUtils.getCurrentUserName();
		logger.debug(loginName);
	}
	/**
	 * list 方法，根据当前用户显示公司详细
	 */
	@Override
	public String list() throws Exception {
		loginName = SpringSecurityUtils.getCurrentUserName();
		logger.debug(loginName);
		page = companyManager.findByUser(page, loginName);
		return SUCCESS;
	}
	public String input() throws Exception {
		return INPUT;
	}
	@Override
	protected void prepareModel() throws Exception {
		if(id!=null){
			entity = companyManager.get(id);
		}else{
			entity = new Company();
		}
		
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	public Company getModel() {
		return entity;
	}
	/**
	 * 下面是一些私有内容，可能不会引起客户的注意
	 */
	private Long id = null;

	private Company entity = null;
	private Page<Company> page = new Page<Company>(10);
	@Autowired
	private CompanyManager companyManager = null;
	private String loginName = null;
	public void setCompany(Company company) {
		this.entity = company;
	}

	public Page<Company> getPage() {
		return page;
	}

	public void setPage(Page<Company> page) {
		this.page = page;
	}

	public CompanyManager getCompanyManager() {
		return companyManager;
	}

	public void setCompanyManager(CompanyManager companyManager) {
		this.companyManager = companyManager;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}

}
